package com.eningqu.aipen.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.ToastUtils;

/**
 * Package:com.eningqu.aipen.ui.view
 * Author:starr
 * Time:2023/11/8 12:55
 * Description:
 */
public class ChatMsgView extends androidx.appcompat.widget.AppCompatTextView {

    public String drawText="正在加载中...";
    public int widthText;
    public int progress;
    private Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
    public ChatMsgView(@NonNull Context context) {
        super(context);
        init();
    }

    public ChatMsgView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ChatMsgView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public int getProgress(){
        return progress;
    }

    public void setProgress(int progress){
        this.progress=progress;
        invalidate();
    }

    public String getDrawText(){
        return drawText;
    }

    void init(){
        Rect bounds=new Rect();
        paint.setTextSize(SizeUtils.dp2px(16));
        paint.getTextBounds(drawText,0,drawText.length(),bounds);
        widthText=bounds.width();
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawText(drawText,0,progress,progress/2-widthText/2,getHeight()/2,paint);
    }
}
